﻿/*----------------------------------------------------------------
// Copyright (C) 2012
// 版权所有
//
// 文件名：VIP.cs
// 文件功能描述：
//
//
// 创建标识：Libing 2012-05-10 01:32:53 星期四
//
// 修改标识：
// 修改描述：
//----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using WMS.DBUtility;

namespace WMS.SQLServerDAL
{
    public class VIP : WMS.IDAL.IVIP
    {
        #region 基本方法

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="vip">类型为 WMS.Model.VIP 的实体</param>
        /// <returns></returns>
        public bool Insert(WMS.Model.VIP vip)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@VIP_NO", SqlDbType.VarChar, 200),
				new SqlParameter("@VIP_NAME", SqlDbType.VarChar, 100),
				new SqlParameter("@VIP_TEL", SqlDbType.VarChar, 100),
				new SqlParameter("@VIP_QQ", SqlDbType.VarChar, 20),
				new SqlParameter("@VIP_EMAIL", SqlDbType.VarChar, 60),
				new SqlParameter("@VIP_ADD", SqlDbType.VarChar, 500),
				new SqlParameter("@VIP_PRO", SqlDbType.VarChar, 500),
				new SqlParameter("@VIP_POST", SqlDbType.VarChar, 100),
				new SqlParameter("@VIP_PHO", SqlDbType.VarChar, 100),
				new SqlParameter("@VIP_ZJLB", SqlDbType.VarChar, 10),
				new SqlParameter("@VIP_ZJNO", SqlDbType.VarChar, 50),
				new SqlParameter("@VIP_DAT", SqlDbType.DateTime, 8),
				new SqlParameter("@VIP_DQ", SqlDbType.VarChar, 32),
				new SqlParameter("@VIP_JSRQ", SqlDbType.DateTime, 8),
				new SqlParameter("@VIP_GLSR", SqlDbType.DateTime, 8),
				new SqlParameter("@VIP_SEX", SqlDbType.VarChar, 4),
				new SqlParameter("@VIP_HF", SqlDbType.VarChar, 10),
				new SqlParameter("@VIP_XL", SqlDbType.VarChar, 20),
				new SqlParameter("@VIP_ZY", SqlDbType.VarChar, 20),
				new SqlParameter("@VIP_MZ", SqlDbType.VarChar, 10),
				new SqlParameter("@VIP_TBJNR", SqlDbType.DateTime, 8),
				new SqlParameter("@CII", SqlDbType.VarChar, 20),
				new SqlParameter("@CIIDES", SqlDbType.VarChar, 200)
			};
            parameters[0].Value = vip.VipNo;
            parameters[1].Value = vip.VipName;
            parameters[2].Value = vip.VipTel;
            parameters[3].Value = vip.VipQq;
            parameters[4].Value = vip.VipEmail;
            parameters[5].Value = vip.VipAdd;
            parameters[6].Value = vip.VipPro;
            parameters[7].Value = vip.VipPost;
            parameters[8].Value = vip.VipPho;
            parameters[9].Value = vip.VipZjlb;
            parameters[10].Value = vip.VipZjno;
            parameters[11].Value = vip.VipDat;
            parameters[12].Value = vip.VipDq;
            parameters[13].Value = vip.VipJsrq;
            parameters[14].Value = vip.VipGlsr;
            parameters[15].Value = vip.VipSex;
            parameters[16].Value = vip.VipHf;
            parameters[17].Value = vip.VipXl;
            parameters[18].Value = vip.VipZy;
            parameters[19].Value = vip.VipMz;
            parameters[20].Value = vip.VipTbjnr;
            parameters[21].Value = vip.Cii;
            parameters[22].Value = vip.Ciides;

            try
            {
                int result = DbHelperSQL.ExecuteStoredProcNonQuery("[VIP_Insert]", parameters);

                return result > 0;
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 修改实体
        /// </summary>
        /// <param name="vip">类型为 WMS.Model.VIP 的实体</param>
        /// <returns></returns>
        public bool Update(WMS.Model.VIP vip)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@VIP_NO", SqlDbType.VarChar, 200),
				new SqlParameter("@VIP_NAME", SqlDbType.VarChar, 100),
				new SqlParameter("@VIP_TEL", SqlDbType.VarChar, 100),
				new SqlParameter("@VIP_QQ", SqlDbType.VarChar, 20),
				new SqlParameter("@VIP_EMAIL", SqlDbType.VarChar, 60),
				new SqlParameter("@VIP_ADD", SqlDbType.VarChar, 500),
				new SqlParameter("@VIP_PRO", SqlDbType.VarChar, 500),
				new SqlParameter("@VIP_POST", SqlDbType.VarChar, 100),
				new SqlParameter("@VIP_PHO", SqlDbType.VarChar, 100),
				new SqlParameter("@VIP_ZJLB", SqlDbType.VarChar, 10),
				new SqlParameter("@VIP_ZJNO", SqlDbType.VarChar, 50),
				new SqlParameter("@VIP_DAT", SqlDbType.DateTime, 8),
				new SqlParameter("@VIP_DQ", SqlDbType.VarChar, 32),
				new SqlParameter("@VIP_JSRQ", SqlDbType.DateTime, 8),
				new SqlParameter("@VIP_GLSR", SqlDbType.DateTime, 8),
				new SqlParameter("@VIP_SEX", SqlDbType.VarChar, 4),
				new SqlParameter("@VIP_HF", SqlDbType.VarChar, 10),
				new SqlParameter("@VIP_XL", SqlDbType.VarChar, 20),
				new SqlParameter("@VIP_ZY", SqlDbType.VarChar, 20),
				new SqlParameter("@VIP_MZ", SqlDbType.VarChar, 10),
				new SqlParameter("@VIP_TBJNR", SqlDbType.DateTime, 8),
				new SqlParameter("@CII", SqlDbType.VarChar, 20),
				new SqlParameter("@CIIDES", SqlDbType.VarChar, 200)
			};
            parameters[0].Value = vip.VipNo;
            parameters[1].Value = vip.VipName;
            parameters[2].Value = vip.VipTel;
            parameters[3].Value = vip.VipQq;
            parameters[4].Value = vip.VipEmail;
            parameters[5].Value = vip.VipAdd;
            parameters[6].Value = vip.VipPro;
            parameters[7].Value = vip.VipPost;
            parameters[8].Value = vip.VipPho;
            parameters[9].Value = vip.VipZjlb;
            parameters[10].Value = vip.VipZjno;
            parameters[11].Value = vip.VipDat;
            parameters[12].Value = vip.VipDq;
            parameters[13].Value = vip.VipJsrq;
            parameters[14].Value = vip.VipGlsr;
            parameters[15].Value = vip.VipSex;
            parameters[16].Value = vip.VipHf;
            parameters[17].Value = vip.VipXl;
            parameters[18].Value = vip.VipZy;
            parameters[19].Value = vip.VipMz;
            parameters[20].Value = vip.VipTbjnr;
            parameters[21].Value = vip.Cii;
            parameters[22].Value = vip.Ciides;

            try
            {
                return DbHelperSQL.ExecuteStoredProcNonQuery("[VIP_Update]", parameters) > 0;
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 最小修改实体
        /// </summary>
        /// <param name="model">类型为WMS.Model.VIP的实体</param>
        /// <returns></returns>
        public bool UpdateMinimal(WMS.Model.VIP vip)
        {
            SqlCommand cmd = new SqlCommand("[VIP_UpdateMinimal]");

            if (vip.VipNo != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_NO", SqlDbType.VarChar, 200)).Value = vip.VipNo;
            }

            if (vip.VipName != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_NAME", SqlDbType.VarChar, 100)).Value = vip.VipName;
            }

            if (vip.VipTel != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_TEL", SqlDbType.VarChar, 100)).Value = vip.VipTel;
            }

            if (vip.VipQq != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_QQ", SqlDbType.VarChar, 20)).Value = vip.VipQq;
            }

            if (vip.VipEmail != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_EMAIL", SqlDbType.VarChar, 60)).Value = vip.VipEmail;
            }

            if (vip.VipAdd != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_ADD", SqlDbType.VarChar, 500)).Value = vip.VipAdd;
            }

            if (vip.VipPro != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_PRO", SqlDbType.VarChar, 500)).Value = vip.VipPro;
            }

            if (vip.VipPost != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_POST", SqlDbType.VarChar, 100)).Value = vip.VipPost;
            }

            if (vip.VipPho != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_PHO", SqlDbType.VarChar, 100)).Value = vip.VipPho;
            }

            if (vip.VipZjlb != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_ZJLB", SqlDbType.VarChar, 10)).Value = vip.VipZjlb;
            }

            if (vip.VipZjno != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_ZJNO", SqlDbType.VarChar, 50)).Value = vip.VipZjno;
            }

            if (vip.VipDat != null)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_DAT", SqlDbType.DateTime, 8)).Value = vip.VipDat;
            }

            if (vip.VipDq != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_DQ", SqlDbType.VarChar, 32)).Value = vip.VipDq;
            }

            if (vip.VipJsrq != null)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_JSRQ", SqlDbType.DateTime, 8)).Value = vip.VipJsrq;
            }

            if (vip.VipGlsr != null)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_GLSR", SqlDbType.DateTime, 8)).Value = vip.VipGlsr;
            }

            if (vip.VipSex != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_SEX", SqlDbType.VarChar, 4)).Value = vip.VipSex;
            }

            if (vip.VipHf != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_HF", SqlDbType.VarChar, 10)).Value = vip.VipHf;
            }

            if (vip.VipXl != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_XL", SqlDbType.VarChar, 20)).Value = vip.VipXl;
            }

            if (vip.VipZy != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_ZY", SqlDbType.VarChar, 20)).Value = vip.VipZy;
            }

            if (vip.VipMz != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_MZ", SqlDbType.VarChar, 10)).Value = vip.VipMz;
            }

            if (vip.VipTbjnr != null)
            {
                cmd.Parameters.Add(new SqlParameter("@VIP_TBJNR", SqlDbType.DateTime, 8)).Value = vip.VipTbjnr;
            }

            if (vip.Cii != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@CII", SqlDbType.VarChar, 20)).Value = vip.Cii;
            }

            if (vip.Ciides != string.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@CIIDES", SqlDbType.VarChar, 200)).Value = vip.Ciides;
            }

            try
            {
                return DbHelperSQL.ExecuteStoredProcNonQuery(cmd) > 0;
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 删除实体(根据主键 VIP_NO)
        /// </summary>
        /// <param name="vipNo">VipNo</param>
        /// <returns></returns>
        public bool DeleteByVIP_NO(string vipNo)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@VIP_NO", SqlDbType.VarChar,200)
			};
            parameters[0].Value = vipNo;

            try
            {
                return DbHelperSQL.ExecuteStoredProcNonQuery("[VIP_DeleteByVIP_NO]", parameters) > 0;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 删除实体(指定条件)
        /// </summary>
        /// <param name="whereClause">WHERE语句</param>
        /// <returns></returns>
        public bool DeleteDynamic(string whereClause)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@WhereClause", SqlDbType.NVarChar,2000)
			};
            parameters[0].Value = whereClause;

            try
            {
                return DbHelperSQL.ExecuteStoredProcNonQuery("[VIP_DeleteDynamic]", parameters) > 0;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 获取实体(根据主键 VIP_NO)
        /// </summary>
        /// <param name="vipNo">VipNo</param>
        /// <returns></returns>
        public WMS.Model.VIP GetByVIP_NO(string vipNo)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@VIP_NO", SqlDbType.VarChar,200)
			};
            parameters[0].Value = vipNo;

            try
            {
                List<WMS.Model.VIP> vipList = new List<WMS.Model.VIP>();

                SqlDataReader dr = DbHelperSQL.ExecuteStoredProcReader("[VIP_GetByVIP_NO]", parameters);
                while (dr.Read())
                {
                    WMS.Model.VIP vip = new WMS.Model.VIP();

                    vip.VipNo = Convert.ToString(dr["VIP_NO"]);
                    vip.VipName = Convert.ToString(dr["VIP_NAME"]);
                    vip.VipTel = Convert.ToString(dr["VIP_TEL"]);
                    vip.VipQq = Convert.ToString(dr["VIP_QQ"]);
                    vip.VipEmail = Convert.ToString(dr["VIP_EMAIL"]);
                    vip.VipAdd = Convert.ToString(dr["VIP_ADD"]);
                    vip.VipPro = Convert.ToString(dr["VIP_PRO"]);
                    vip.VipPost = Convert.ToString(dr["VIP_POST"]);
                    vip.VipPho = Convert.ToString(dr["VIP_PHO"]);
                    vip.VipZjlb = Convert.ToString(dr["VIP_ZJLB"]);
                    vip.VipZjno = Convert.ToString(dr["VIP_ZJNO"]);
                    vip.VipDat = Convert.ToDateTime(dr["VIP_DAT"]).ToString("yyyy-MM-dd");
                    vip.VipDq = Convert.ToString(dr["VIP_DQ"]);
                    vip.VipJsrq = Convert.ToDateTime(dr["VIP_JSRQ"]).ToString("yyyy-MM-dd");
                    vip.VipGlsr = Convert.ToDateTime(dr["VIP_GLSR"]).ToString("yyyy-MM-dd");
                    vip.VipSex = Convert.ToString(dr["VIP_SEX"]);
                    vip.VipHf = Convert.ToString(dr["VIP_HF"]);
                    vip.VipXl = Convert.ToString(dr["VIP_XL"]);
                    vip.VipZy = Convert.ToString(dr["VIP_ZY"]);
                    vip.VipMz = Convert.ToString(dr["VIP_MZ"]);
                    vip.VipTbjnr = Convert.ToDateTime(dr["VIP_TBJNR"]).ToString("yyyy-MM-dd");
                    vip.Cii = Convert.ToString(dr["CII"]);
                    vip.Ciides = Convert.ToString(dr["CIIDES"]);
                    vip.ModelState = WMS.Model.Enum.ModelState.None;

                    vipList.Add(vip);
                }

                // Close the dr, which will cause the connection to be closed as well.
                dr.Close();

                if (vipList.Count > 0)
                {
                    return vipList[0];
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        #endregion

        #region	公共方法

        /// <summary>
        /// 获取实体列表(指定数目和查询条件)
        /// </summary>
        /// <param name="topClause">指定实体数</param>
        /// <param name="whereClause">WHERE语句</param>
        /// <returns></returns>
        public List<WMS.Model.VIP> Get(int topClause, string whereClause)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@TopClause", SqlDbType.Int,4),
				new SqlParameter("@WhereClause", SqlDbType.NVarChar,2000)
			};
            parameters[0].Value = topClause;
            parameters[1].Value = whereClause;

            try
            {
                List<WMS.Model.VIP> vipList = new List<WMS.Model.VIP>();

                SqlDataReader dr = DbHelperSQL.ExecuteStoredProcReader("[VIP_GetDynamic]", parameters);
                while (dr.Read())
                {
                    WMS.Model.VIP vip = new WMS.Model.VIP();

                    vip.VipNo = Convert.ToString(dr["VIP_NO"]);
                    vip.VipName = Convert.ToString(dr["VIP_NAME"]);
                    vip.VipTel = Convert.ToString(dr["VIP_TEL"]);
                    vip.VipQq = Convert.ToString(dr["VIP_QQ"]);
                    vip.VipEmail = Convert.ToString(dr["VIP_EMAIL"]);
                    vip.VipAdd = Convert.ToString(dr["VIP_ADD"]);
                    vip.VipPro = Convert.ToString(dr["VIP_PRO"]);
                    vip.VipPost = Convert.ToString(dr["VIP_POST"]);
                    vip.VipPho = Convert.ToString(dr["VIP_PHO"]);
                    vip.VipZjlb = Convert.ToString(dr["VIP_ZJLB"]);
                    vip.VipZjno = Convert.ToString(dr["VIP_ZJNO"]);
                    vip.VipDat = Convert.ToDateTime(dr["VIP_DAT"]).ToString("yyyy-MM-dd");
                    vip.VipDq = Convert.ToString(dr["VIP_DQ"]);
                    vip.VipJsrq = Convert.ToDateTime(dr["VIP_JSRQ"]).ToString("yyyy-MM-dd");
                    vip.VipGlsr = Convert.ToDateTime(dr["VIP_GLSR"]).ToString("yyyy-MM-dd");
                    vip.VipSex = Convert.ToString(dr["VIP_SEX"]);
                    vip.VipHf = Convert.ToString(dr["VIP_HF"]);
                    vip.VipXl = Convert.ToString(dr["VIP_XL"]);
                    vip.VipZy = Convert.ToString(dr["VIP_ZY"]);
                    vip.VipMz = Convert.ToString(dr["VIP_MZ"]);
                    vip.VipTbjnr = Convert.ToDateTime(dr["VIP_TBJNR"]).ToString("yyyy-MM-dd");
                    vip.Cii = Convert.ToString(dr["CII"]);
                    vip.Ciides = Convert.ToString(dr["CIIDES"]);
                    vip.ModelState = WMS.Model.Enum.ModelState.None;

                    vipList.Add(vip);
                }

                // Close the dr, which will cause the connection to be closed as well.
                dr.Close();

                return vipList;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 获取实体列表(指定查询条件)
        /// </summary>
        /// <param name="whereClause">WHERE语句</param>
        /// <returns></returns>
        public List<WMS.Model.VIP> Get(string whereClause)
        {
            return Get(0, whereClause);
        }

        /// <summary>
        /// 获取分页实体列表
        /// </summary>
        /// <param name="whereClause">WHERE 语句</param>
        /// <param name="orderByClause">ORDER BY 语句</param>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="pageSize">分页大小(每页显示的记录数)</param>
        /// <param name="totalRecords">记录总数</param>
        /// <returns></returns>
        public List<WMS.Model.VIP> GetPaged(string whereClause, string orderBy, int pageIndex, int pageSize, out int totalRecords)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@WhereClause", SqlDbType.NVarChar, 2000),
				new SqlParameter("@OrderBy", SqlDbType.NVarChar, 1000),
				new SqlParameter("@PageIndex", SqlDbType.Int, 4),
				new SqlParameter("@PageSize", SqlDbType.Int, 4)
			};
            parameters[0].Value = whereClause;
            parameters[1].Value = orderBy;
            parameters[2].Value = pageIndex;
            parameters[3].Value = pageSize;

            try
            {
                List<WMS.Model.VIP> vipList = new List<WMS.Model.VIP>();

                SqlDataReader dr = DbHelperSQL.ExecuteStoredProcReader("[VIP_GetPaged]", parameters);
                while (dr.Read())
                {
                    WMS.Model.VIP vip = new WMS.Model.VIP();

                    vip.VipNo = Convert.ToString(dr["VIP_NO"]);
                    vip.VipName = Convert.ToString(dr["VIP_NAME"]);
                    vip.VipTel = Convert.ToString(dr["VIP_TEL"]);
                    vip.VipQq = Convert.ToString(dr["VIP_QQ"]);
                    vip.VipEmail = Convert.ToString(dr["VIP_EMAIL"]);
                    vip.VipAdd = Convert.ToString(dr["VIP_ADD"]);
                    vip.VipPro = Convert.ToString(dr["VIP_PRO"]);
                    vip.VipPost = Convert.ToString(dr["VIP_POST"]);
                    vip.VipPho = Convert.ToString(dr["VIP_PHO"]);
                    vip.VipZjlb = Convert.ToString(dr["VIP_ZJLB"]);
                    vip.VipZjno = Convert.ToString(dr["VIP_ZJNO"]);
                    vip.VipDat = Convert.ToDateTime(dr["VIP_DAT"]).ToString("yyyy-MM-dd");
                    vip.VipDq = Convert.ToString(dr["VIP_DQ"]);
                    vip.VipJsrq = Convert.ToDateTime(dr["VIP_JSRQ"]).ToString("yyyy-MM-dd");
                    vip.VipGlsr = Convert.ToDateTime(dr["VIP_GLSR"]).ToString("yyyy-MM-dd");
                    vip.VipSex = Convert.ToString(dr["VIP_SEX"]);
                    vip.VipHf = Convert.ToString(dr["VIP_HF"]);
                    vip.VipXl = Convert.ToString(dr["VIP_XL"]);
                    vip.VipZy = Convert.ToString(dr["VIP_ZY"]);
                    vip.VipMz = Convert.ToString(dr["VIP_MZ"]);
                    vip.VipTbjnr = Convert.ToDateTime(dr["VIP_TBJNR"]).ToString("yyyy-MM-dd");
                    vip.Cii = Convert.ToString(dr["CII"]);
                    vip.Ciides = Convert.ToString(dr["CIIDES"]);
                    vip.ModelState = WMS.Model.Enum.ModelState.None;

                    vipList.Add(vip);
                }

                totalRecords = vipList.Count;

                if (dr.NextResult())
                {
                    if (dr.Read())
                    {
                        totalRecords = Convert.ToInt32(dr[0]);
                    }
                }

                // Close the dr, which will cause the connection to be closed as well.
                dr.Close();

                return vipList;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        #endregion

        #region 自定义方法

        /// <summary>
        /// 根据过滤条件获取分页实体列表
        /// </summary>
        /// <param name="vipNo">VIP卡号</param>
        /// <param name="vipName">姓名</param>
        /// <param name="cii">店铺代码</param>
        /// <param name="vipZjno">证件号码</param>
        /// <param name="vipDq">发卡地区</param>
        /// <param name="startVipDat">发卡日期-起始</param>
        /// <param name="endVipDat">发卡日期-截止</param>
        /// <param name="startVipJsrq">有效期-起始</param>
        /// <param name="endVipJsrq">有效期-截止</param>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="pageSize">分页大小(每页显示的记录数)</param>
        /// <param name="totalRecords">记录总数</param>
        /// <returns></returns>
        public List<WMS.Model.VIP> GetFilterPaged(string vipNo, string vipName, string cii, string vipZjno, string vipDq, string startVipDat, string endVipDat, string startVipJsrq, string endVipJsrq, int pageIndex, int pageSize, out int totalRecords)
        {
            StringBuilder whereClause = new StringBuilder();
            whereClause.Append("1=1");

            if (!String.IsNullOrEmpty(vipNo))
            {
                whereClause.AppendFormat(" AND VIP_NO LIKE '%{0}%'", vipNo);
            }
            if (!String.IsNullOrEmpty(vipName))
            {
                whereClause.AppendFormat(" AND VIP_NAME LIKE '%{0}%'", vipName);
            }
            if (!String.IsNullOrEmpty(cii))
            {
                whereClause.AppendFormat(" AND CII LIKE '%{0}%'", cii);
            }
            if (!String.IsNullOrEmpty(vipZjno))
            {
                whereClause.AppendFormat(" AND VIP_ZJNO LIKE '%{0}%'", vipZjno);
            }
            if (!String.IsNullOrEmpty(vipDq))
            {
                whereClause.AppendFormat(" AND VIP_DQ LIKE '%{0}%'", vipDq);
            }
            if (!String.IsNullOrEmpty(startVipDat))
            {
                whereClause.AppendFormat(" AND VIP_DAT >= '{0}'", startVipDat);
            }
            if (!String.IsNullOrEmpty(endVipDat))
            {
                whereClause.AppendFormat(" AND VIP_DAT < '{0}'", Convert.ToDateTime(endVipDat).AddDays(1).ToString("yyyy-MM-dd"));
            }
            if (!String.IsNullOrEmpty(startVipJsrq))
            {
                whereClause.AppendFormat(" AND VIP_JSRQ >= '{0}'", startVipJsrq);
            }
            if (!String.IsNullOrEmpty(endVipJsrq))
            {
                whereClause.AppendFormat(" AND VIP_JSRQ < '{0}'", Convert.ToDateTime(endVipJsrq).AddDays(1).ToString("yyyy-MM-dd"));
            }

            return GetPaged(whereClause.ToString(), "VIP_DAT DESC", pageIndex, pageSize, out totalRecords);
        }

        /// <summary>
        /// 判断VIP编号是否已存在
        /// </summary>
        /// <param name="vipNo">VIP编号</param>
        /// <returns></returns>
        public bool Exists(string vipNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat("SELECT COUNT(1) FROM VIP WHERE VIP_NO='{0}'", vipNo);

            return Convert.ToInt32(DbHelperSQL.ExecuteSqlStringScalar(strSql.ToString())) > 0;
        }

        #endregion
    }
}
